package cums.db.impl;

import cums.db.iface.GroupsDao;
import cums.db.pers.Groups;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @time Dec 9, 2009, 12:49:03 PM
 * @author fdcube
 */
public class GroupsImpl extends HibernateDaoSupport implements GroupsDao {

    public Groups AddOrUpdateGroups(Groups value) {
        this.getHibernateTemplate().saveOrUpdate(value);
        return value;
    }

    public boolean DeleteGroups(Groups value) {
        try {
            this.getHibernateTemplate().delete(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public List<Groups> ListGroups() {
        return this.getHibernateTemplate().find("FROM GROUPS ORDER BY GID");
    }

    public List<Groups> FindGroupsByGid(int value) {
        return this.getHibernateTemplate().findByNamedParam("FROM GROUPS AS g WHERE g.GID =:value", "value", value);
    }

    public List<Groups> FindGroupsByGname(String value) {
        return this.getHibernateTemplate().findByNamedParam("FROM GROUPS AS g WHERE g.gname=:value", "value", value);
    }
}
